package com.javaweb.blogcite.controller.vo;

import com.javaweb.blogcite.pojo.Project;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProjectView {
        private Integer id;
        private String name;
        private String url;
        private List<String> description;
        private String thumb;
        private String github;
        private Integer order;

    /**
     * 根据数据库查询到的 Project 信息，转化为可以返回给前端的 ProjectView 信息
     * @param project
     */
    public ProjectView(Project project) {
        this.id = project.getId();
        this.name = project.getName();
        this.url = project.getUrl();
        this.thumb = project.getThumb();
        this.github = project.getGithub();
        this.order = project.getOrder();
        // 获取 description 并按逗号分割成字符串列表
        String description = project.getDescription();
        String[] tests = description.split(",");
        this.description = Arrays.asList(tests);
    }
}
